package com.example.fill.xui;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.SurfaceHolder;
import android.view.SurfaceView;

import androidx.annotation.NonNull;

public class Vkkkkkkkkkk extends SurfaceView implements SurfaceHolder.Callback {
    public Vkkkkkkkkkk(Context context) {
        super(context);
        getHolder().addCallback(this);
    }

    public Vkkkkkkkkkk(Context context, AttributeSet attrs) {
        super(context, attrs);
        getHolder().addCallback(this);

    }

    public Vkkkkkkkkkk(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        getHolder().addCallback(this);

    }

    public Vkkkkkkkkkk(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        getHolder().addCallback(this);

    }

    boolean run = true;
    Thread t;
    @Override
    public void surfaceCreated(@NonNull SurfaceHolder holder) {
        t = new Thread(new Runnable() {
            @Override
            public void run() {
                while (run){
                    Canvas canvas = holder.lockCanvas();
                    if (canvas == null) return;
                    canvas.drawColor(Color.WHITE);
                    holder.unlockCanvasAndPost(canvas);
                }
            }
        });
        t.start();
    }

    @Override
    public void surfaceChanged(@NonNull SurfaceHolder holder, int format, int width, int height) {

    }

    @Override
    public void surfaceDestroyed(@NonNull SurfaceHolder holder) {
        if (t == null) return;
        while (t.isAlive()){
            run = false;
        }
        t = null;
    }
}
